package com.example.controller;

import com.example.anno.SysLog;
import com.example.entity.Test;
import com.example.entity.User;
import com.example.service.TestService;
import com.example.service.UserService;
import io.netty.util.HashedWheelTimer;
import io.netty.util.concurrent.DefaultThreadFactory;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/testBoot")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private TestService testService;
    @SysLog
    @RequestMapping("getUser/{id}")
    public Object GetUser(@PathVariable(value = "id") @ApiParam(value = "id", example = "1", required = true) Integer id) {
        return  userService.Sel(id);
    }

    @RequestMapping(value = "/test/", method = RequestMethod.POST)
    public Object postUser(@RequestBody User user) {
        return userService.add(user);
    }

    @RequestMapping(value = "/test/{id}", method = RequestMethod.PUT)
    public Object putUser(@PathVariable Integer id, @RequestBody User user) {
        return userService.update(id, user);
    }

    @RequestMapping(value = "/test/{id}", method = RequestMethod.DELETE)
    public Object delUser(@PathVariable Integer id) {
        return userService.del(id);
    }

    @RequestMapping("/test")
    public List<User> ListUser(){
        return userService.ListUser();
    }

    @RequestMapping("/test1")
    public Test ListUser1(){
        Test test = new Test();
        test.setName("22");

        return testService.update(1,test);
    }

    @RequestMapping("/test2")
    public Test ListUser2(){
        Test test = new Test();
        test.setName("22");
        test.setCreateTime(LocalDateTime.now());
        test.setUpdateTime(LocalDateTime.now());
        return testService.add(test);
    }


    HashedWheelTimer hashedWheelTimer= new HashedWheelTimer(
            new DefaultThreadFactory("demo"),100, TimeUnit.MICROSECONDS,10,false
    );

    @RequestMapping("dd/{id}")
    public void test(@PathVariable Long id) {
        hashedWheelTimer.newTimeout(timeout -> {
            System.out.println("sss:"+LocalDateTime.now());
        },id,TimeUnit.SECONDS);
    }



}
